package mulMan.gui.view;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mulMan.domain.Playlist;

public abstract class PlaylistView extends JFrame  implements Observer {

	private static final long serialVersionUID = -1833973059123903566L;
	
	private Playlist playlist;
	private JLabel nameLabel;
	private JTextField nameTextField;
	private JPanel panel;
	private JLabel errorLabel;
	
	public JTextField getNameTextField() {
		return nameTextField;
	}
	public JLabel getNameLabel() {
		return nameLabel;
	}
	public void setNameLabel(JLabel nameLabel) {
		this.nameLabel = nameLabel;
	}
	public void setNameTextField(JTextField nameTextField) {
		this.nameTextField = nameTextField;
	}
	public JPanel getPanel() {
		return panel;
	}
	public void setPanel(JPanel panel) {
		this.panel = panel;
	}
	public JLabel getErrorLabel() {
		return errorLabel;
	}
	public void setErrorLabel(JLabel errorLabel) {
		this.errorLabel = errorLabel;
	}
	
	
	public PlaylistView(Playlist playlist) {
		this.playlist = playlist;
		this.playlist.addObserver(this);
		
		initView();
	    initFields();
	}

	public void update(Observable o, Object arg) {
		if (arg == "name") {
			nameTextField.setText(playlist.getName());
		}
	}

	public void initView() {
		panel = new JPanel();
	    getContentPane().add(panel);
	    panel.setLayout(null);
	       
	    
		setTitle("Playlist window");
	    setSize(250, 105);
	    setResizable(false);
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	    setVisible(true);
	    
	    nameLabel = new JLabel();
	    nameLabel.setText("name: ");
	    nameLabel.setBounds(5, 5, 80, 20);
	    panel.add(nameLabel);
	    nameTextField = new JTextField();
	    nameTextField.setBounds(50, 5, 190, 20);
	    panel.add(nameTextField);
	    
	    errorLabel = new JLabel();
	    errorLabel.setText("");
	    errorLabel.setForeground(Color.RED);
	    errorLabel.setBounds(5, 25, 235, 20);
	    panel.add(errorLabel);
	}
	
	public void initFields() {
		nameTextField.setText(playlist.getName());
	}
	
	public void resetErrors() {
		getNameLabel().setForeground(Color.BLACK);
		getErrorLabel().setText("");
	}
	
}
